package org.mozhu.mboot.core.web.resource;

import lombok.extern.slf4j.Slf4j;
import org.mozhu.mboot.core.config.ApplicationConfiguration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;

@Slf4j
public class StaticWebResourceConfigurer extends BaseWebResourceConfigurer {
    // web.static 指定静态资源的路径，如http://static.xxx.com
    private static final String PROPERTY_KEY_WEB_STATIC_DOMAIN = "web.static.domain";

    public void addResourceHandler(ResourceHandlerRegistry registry) {
        String webStatic = ApplicationConfiguration.get().getProperty(PROPERTY_KEY_WEB_STATIC_DOMAIN, "");
        webStatic = trimLastSlash(webStatic);
        servletContext.setAttribute(PROPERTY_KEY_WEB_STATIC_DOMAIN, webStatic);
        log.info("Set [{}] to [{}]", PROPERTY_KEY_WEB_STATIC_DOMAIN, webStatic);
    }

}
